﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using V5_Common;
using V5_BLL;
using V5_Model;
using System.Data;

namespace V5_EShop._Template.Default
{
    public partial class product_allcomments : BasicPage
    {
        public ModelProduct product = new ModelProduct();
        public ModelUser m_user = new ModelUser();
        int proid = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                proid = Input.SetInt(Request["productid"]);
                if (proid > 0)
                {
                    Bind_CommentList();
                }
                else
                {
                    Response.Redirect("/index.aspx");
                }
            }
        }
        /// <summary>
        /// 绑定评论
        /// </summary>
        private void Bind_CommentList()
        {
            string strWhere = "";
            int count = 0;
            if (proid > 0)
            {
                strWhere = " ProductID=" + proid;
            }
            this.rpCommentList.DataSource = new BLLProductComment().GetList(Pager.PageSize,
                Pager.CurrentPageIndex,
                strWhere,
                ref count);
            this.Pager.RecordCount = count;
            this.rpCommentList.DataBind();
            //绑定产品信息
            product = new BLLProduct().GetModel(proid);
        }

        protected void Pager_PageChanged(object sender, EventArgs e)
        {
            Bind_CommentList();
        }

        /// <summary>
        /// 获取评价
        /// </summary>
        /// <param name="oPostID">评价ID 1,2,3</param>
        /// <param name="showType">评价类型 1,2,3,4</param>
        /// <returns></returns>
        public string Get_Post(object oProductID, string oPostID, string showType)
        {
            int iProductID = Input.SetInt(oProductID);
            int PostID = Input.SetInt(oPostID);
            string Count = "0";
            DataTable dt = new DataTable();
            switch (showType)
            {
                case "1":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost=" + PostID).Tables[0];
                    Count = dt.Rows.Count.ToString();
                    break;
                case "2":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost1=" + PostID).Tables[0];
                    Count = dt.Rows.Count.ToString();
                    break;
                case "3":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost2=" + PostID).Tables[0];
                    Count = dt.Rows.Count.ToString();
                    break;
                default:
                    break;
            }
            return Count;
        }

        /// <summary>
        /// 返回 合适度
        /// </summary>
        /// <param name="oProductID"></param>
        /// <param name="showType"></param>
        /// <returns></returns>
        public string Get_ShuShi(object oProductID, string showType)
        {
            int iProductID = Input.SetInt(oProductID);
            string persent = "0";
            DataTable dt = new BLLProductComment().GetList(" ProductID=" + iProductID).Tables[0];
            int Count = dt.Rows.Count;
            int temp = 0;
            switch (showType)
            {
                case "1":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost2=1 ").Tables[0];
                    temp = dt.Rows.Count;
                    persent = ((temp / Count) * 100).ToString();
                    break;
                case "2":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost2=2 ").Tables[0];
                    temp = dt.Rows.Count;
                    persent = ((temp / Count) * 100).ToString();
                    break;
                case "3":
                    dt = new BLLProductComment().GetList(" ProductID=" + iProductID + " and Pmost2=3 ").Tables[0];
                    temp = dt.Rows.Count;
                    persent = ((temp / Count) * 100).ToString();
                    break;
                default:
                    break;
            }
            return persent;
        }
    }
}
